package com.lin.eat.controller;

import com.alibaba.fastjson.JSONObject;
import com.lin.eat.entry.Order;
import com.lin.eat.entry.OrderComment;
import com.lin.eat.entry.ServerResponse;
import com.lin.eat.serivce.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 提交订单
     * @param order
     * @param request
     * @return
     */
    @PostMapping("/submitOrder")
    public ServerResponse<JSONObject> submitOrder(@RequestBody Order order, HttpServletRequest request){
        String token = request.getHeader("token");
        return orderService.submitOrder(order,token);
    }

    /**
     * 获取订单详情
     * @param o_id
     * @return
     */
    @GetMapping ("/getOrderDetail/{o_id}")
    public ServerResponse<Order> getOrderDetail(@PathVariable("o_id") String o_id){
        return orderService.getOrderDetail(o_id);
    }

    /**
     * 支付订单
     * @param o_id
     * @return
     */
    @GetMapping ("/updateOrderState/{o_id}")
    public ServerResponse updateOrderState(@PathVariable("o_id") String o_id){
        return orderService.updateOrderState(o_id);
    }

    /**
     * 获取所有订单
     * @return
     */
    @GetMapping ("/getAllOrder")
    public ServerResponse<List<Order>> getAllOrder(){
        return orderService.getAllOrder();
    }

    /**
     * 删除订单
     * @param o_id
     * @return
     */
    @GetMapping ("/deleteOrder/{o_id}")
    public ServerResponse deleteOrder(@PathVariable("o_id") String o_id){
        return orderService.deleteOrder(o_id);
    }

    /**
     * 提交评论
     * @param orderComment
     * @return
     */
    @PostMapping("/submitOrderComment")
    public ServerResponse submitOrderComment(@RequestBody OrderComment orderComment){
        return orderService.submitOrderComment(orderComment);
    }

}
